import * as apiService from '@/services/api'

/**
 * 取得公告列表
 * @param params
 * @returns {Promise<*>}
 */
const noticeAnnouncementListApi = (params) => {
  return apiService.post(api.NOTICE_ANNOUNCEMENT_LIST,
    params);
};

/**
 * 新建/保存通告
 */
const noticeAnnouncementSaveApi = (params) => {
  const { id, showClient, content, effectiveDate, endDate, name, summary, userType } = params
  if (_.isUndefined(id)) {
    return apiService.post(api.NOTICE_ANNOUNCEMENT_SAVE,
      { showClient, content, effectiveDate, endDate, name, summary, userType });
  }
  return apiService.post(api.NOTICE_ANNOUNCEMENT_UPDATE, { id, showClient, content, effectiveDate, endDate, name, summary, userType });
};

/**
 * 修改公告
 * @param id
 * @returns {Promise<*>}
 */
const noticeAnnouncementEditApi = ({ id }) => {
  return apiService.post(api.NOTICE_ANNOUNCEMENT_DETAIL, { id });
};

/**
 * 删除公告
 * @param params
 * @returns {Promise<*>}
 */
const noticeAnnouncementDeleteApi = ({ id }) => {
  return apiService.post(api.NOTICE_ANNOUNCEMENT_DELETE,
    { id });
};
/**
 * 恢复/收回系统公告
 * @param id
 * @param status
 * @return {Promise<*>}
 */
const noticeAnnouncementToggleStatus = ({ id, status }) => {
  return apiService.post(api.NOTICE_ANNOUNCEMENT_STATUS,
    { id, status });
};
/**
 * 恢复/收回系统弹窗
 * @param id
 * @param status
 * @return {Promise<*>}
 */
const noticeDashboardDialogUpdateStatus = ({ id, status }) => {
  return apiService.post(api.NOTICE_DIALOG_STATUS,
    { id, status });
};

/**
 * 获取公告修改人
 * @returns {Promise<*>}
 */
const noticeOperatorApi = () => {
  return apiService.post(api.NOTICE_OPERATOR);
}
/**
 * 获取消息修改人
 * @returns {Promise<*>}
 */
const dialogOperatorApi = () => {
  return apiService.post(api.DIALOG_OPERATOR);
}

/**
 * 获取消息列表
 * @param params
 * @return {Promise<*>}
 */
const noticeDashboardDialogListApi = (params) => {
  return apiService.post(api.NOTICE_DIALOG_LIST,
    params);
};

/**
 * 新建/保存普通消息
 */
const noticeDashboardNormalDialogSaveApi = (params) => {
  const { id, showClient, name, summary, startTime, endTime, userType, bigImage, url, content, actionTarget, contentType, actionType } = params
  if (_.isUndefined(id)) {
    return apiService.post(api.NOTICE_NORMAL_DIALOG_SAVE,
      { showClient, name, summary, startTime, endTime, userType, bigImage, url, content, actionTarget, contentType, actionType });
  }
  return apiService.post(api.NOTICE_NORMAL_DIALOG_UPDATE,
    { id, showClient, name, summary, startTime, endTime, userType, bigImage, url, content, actionTarget, contentType, actionType });
};

/**
 * 修改普通消息
 * @param id
 * @returns {Promise<*>}
 */
const noticeDashboardNormalDialogEditApi = (id) => {

  return apiService.post(api.NOTICE_NORMAL_DIALOG_DETAIL, { id });
};

/**
 * 删除消息
 * @param id
 * @returns {Promise<*>}
 */
const noticeDashboardDialogDeleteApi = ({ id }) => {
  return apiService.post(api.NOTICE_DIALOG_DELETE,
    { id });
};


/**
 * 新建/保存银行消息
 */
const noticeDashboardBankDialogSaveApi = (params) => {
  const { id, showClient, name, summary, startTime, endTime, userLevel, payment, newBankName, newUsername, bankName, username } = params
  if (_.isUndefined(id)) {
    return apiService.post(api.NOTICE_BANK_DIALOG_SAVE,
      { showClient, name, summary, startTime, endTime, userLevel, payment, newBankName, newUsername, bankName, username });
  }
  return apiService.post(api.NOTICE_BANK_DIALOG_UPDATE, { id, showClient, name, summary, startTime, endTime, userLevel, payment, newBankName, newUsername, bankName, username });
};

/**
 * 修改修改消息
 * @param id
 * @returns {Promise<*>}
 */
const noticeDashboardBanklDialogEditApi = (id) => {
  return apiService.post(api.NOTICE_BANK_DIALOG_DETAIL, { id });
};

/**
 * 获取帮助列表
 * @param params
 * @return {Promise<*>}
 */
const noticeHelpListApi = (params) => {
  return apiService.post(api.NOTICE_HELP_LIST,
    params);
};

/**
 * 帮助详情
 * @param id
 * @returns {Promise<*>}
 */
const noticeHelpDetailApi = (id) => {
  return apiService.post(api.NOTICE_HELP_DETAIL, { id });
};

/**
 * 新建/保存帮助
 */
const noticeHelpSaveApi = (params) => {
  return apiService.post(api.NOTICE_HELP_SAVE,
    params);
};

/**
 * 获取充值教程列表
 * @param params
 * @return {Promise<*>}
 */
const noticeRechargeHelpListApi = (params) => {
  return apiService.post(api.NOTICE_RECHARGE_HELP_LIST,
    params);
};

/**
 * 充值教程详情
 * @param id
 * @returns {Promise<*>}
 */
const noticeRechargeHelpDetailApi = (id) => {
  return apiService.post(api.NOTICE_RECHARGE_HELP_DETAIL, { id });
};

/**
 * 新建/保存充值教程
 */
const noticeRechargeHelpSaveApi = (params) => {
  return apiService.post(api.NOTICE_RECHARGE_HELP_SAVE,
    params);
};

/**
 * 取得收信箱列表
 */
const noticeInBoxManageListApi = (params) => {
  return apiService.post(api.NOTICE_INBOX_LIST, params);
}

/**
 * 取得发信箱列表
 */
const noticePostBoxManageListApi = (params) => {
  let {state,memberLevelId,memberLevelName} = params;
  if(memberLevelId.length){
    memberLevelId = memberLevelId.join(',');
  }
  if(state === -1){
    state = ''
  }

  return apiService.post(api.NOTICE_POSTBOX_LIST,
    {
      ...params,
      state:state,
      memberLevelId:memberLevelId,
    });
}

/**
 * 新建/保存发件箱消息
 */
const noticeLetterAddApi = (params) => {
  let { id, memberLevelId, memberLevelName, memberAccount, letterType, title, content, sendTime } = params
  if (letterType) {
    letterType = 1;
  } else {
    letterType = 0;
  }
  if(_.isUndefined(memberLevelId)){
    memberLevelName = '';
    memberLevelId = '';
  }
  if(_.isUndefined(memberAccount)){
    memberAccount = '';
  }
  if (id==='undefined') {
    return apiService.post(api.NOTICE_LETTER_ADD,
      { memberLevelId, memberLevelName, memberAccount, letterType, title, content, sendTime });
  }
  return apiService.post(api.NOTICE_LETTER_UPDATE,
    { id, memberLevelId, memberLevelName, memberAccount, letterType, title, content, sendTime });
};
/**
 * 删除发信箱消息
 * @param id
 * @returns {Promise<*>}
 */
const noticeLetterDeleteApi = ({ id }) => {
  return apiService.post(api.NOTICE_LETTER_Delete,
    { id });
};
/**
 * 快速回复收件箱消息
 */
const noticeReplyLetterApi = (params) => {
  console.log(params);
  let { id, content, sendTime } = params
  return apiService.post(api.NOTICE_INBOX_REPLY,
    {
      id,
      content,
      sendTime
    });
};
/**
 * 快速回复收件箱消息
 */
const noticeUploadLetterApi = (params) => {
  let { id, content, sendTime } = params
  return apiService.post(api.NOTICE_INBOX_UPDATE,
    {
      id,
      content,
      sendTime
    });
};
/**
 * 收信箱撤回
 * @param id
 * @returns {Promise<*>}
 */
const noticeLetterRevokeApi = ({ id }) => {
  return apiService.post(api.NOTICE_INBOX_REVOKE,
    { id });
};

/**
 * 获取消息列表
 * @param params
 * @return {Promise<*>}
 */
const noticeLetterIsreadListApi = (params) => {
  let {isRead} = params;
  if(isRead === -1){
    isRead = '';
  }
  return apiService.post(api.NOTICE_LETTER_QUERYISREAD,
    {
      ...params,
      isRead:isRead
    });
};

/**
 * 查看收信箱详情
 * @param id
 * @returns {Promise<*>}
 */
const noticeCheckLetterApi = ({ id }) => {
  return apiService.post(api.NOTICE_CHECK_LETTER,
    { id });
};

/**
 * 查看发信箱详情
 * @param id
 * @returns {Promise<*>}
 */
const noticePostboxCheckLetterApi = ({ id }) => {
  return apiService.post(api.NOTICE_POSTBOX_CHECK_LETTER,
    { id });
};


export {
  noticeAnnouncementSaveApi,
  noticeOperatorApi,
  dialogOperatorApi,
  noticeAnnouncementListApi,
  noticeAnnouncementDeleteApi,
  noticeAnnouncementEditApi,
  noticeDashboardDialogListApi,
  noticeDashboardDialogDeleteApi,
  noticeDashboardNormalDialogSaveApi,
  noticeDashboardNormalDialogEditApi,
  noticeDashboardBankDialogSaveApi,
  noticeDashboardBanklDialogEditApi,
  noticeHelpListApi,
  noticeHelpDetailApi,
  noticeHelpSaveApi,
  noticeRechargeHelpListApi,
  noticeRechargeHelpDetailApi,
  noticeRechargeHelpSaveApi,
  noticeAnnouncementToggleStatus,
  noticeDashboardDialogUpdateStatus,
  noticeInBoxManageListApi,
  noticePostBoxManageListApi,
  noticeLetterAddApi,
  noticeLetterDeleteApi,
  noticeReplyLetterApi,
  noticeUploadLetterApi,
  noticeLetterRevokeApi,
  noticeLetterIsreadListApi,
  noticeCheckLetterApi,
  noticePostboxCheckLetterApi
};
